home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume24 / gnudiff1.15 / part01 next >
Encoding:
Internet Message Format  |  1991-03-05  |  48.1 KB

  1. Subject:  v24i016:  GNU Diff, version 1.15, Part01/08
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 757b9767 fc5b0ddd 339090ba 548b3d5c
  5.  
  6. Submitted-by: Paul Eggert <eggert@twinsun.com>
  7. Posting-number: Volume 24, Issue 16
  8. Archive-name: gnudiff1.15/part01
  9.  
  10. This is GNU DIFF 1.15.  As well as many minor improvements, this version has
  11. the following new features:
  12.  
  13.     -u (+unified) option for new unified diff format
  14.     -L (+file-label) option
  15.     -a and -m options for diff3
  16.     Most output styles can represent incomplete input lines.
  17.     `Text' is defined by ISO 8859.
  18.     diff3 exit status 0 means success, 1 means overlaps, 2 means trouble.
  19.  
  20. Please see the README file for more information.
  21. Please report bugs to bug-gnu-utils@prep.ai.mit.edu.
  22.  
  23. #! /bin/sh
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of archive 1 (of 8)."
  30. # Contents:  MANIFEST Makefile README alloca.c diagmeet.note dir.c ed.c
  31. #   getopt.h getopt1.c ifdef.c limits.h normal.c version.c
  32. # Wrapped by eggert@ata on Mon Jan  7 11:25:28 1991
  33. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  34. if test -f 'README' -a "${1}" != "-c" ; then 
  35.   echo shar: Will not clobber existing file \"'README'\"
  36. else
  37. echo shar: Extracting \"'README'\" \(5997 characters\)
  38. sed "s/^X//" >'README' <<'END_OF_FILE'
  39. XThis directory contains the GNU DIFF and DIFF3 utilities, version 1.15.
  40. XSee file COPYING for copying conditions.  To compile and install on
  41. Xsystem V, you must edit the makefile according to comments therein.
  42. X
  43. XReport bugs to bug-gnu-utils@prep.ai.mit.edu
  44. X
  45. XVersion 1.15 has the following new features; please see below for details.
  46. X
  47. X   -L (+file-label) option
  48. X   -u (+unified) option
  49. X   -a and -m options for diff3
  50. X   Most output styles can represent incomplete input lines.
  51. X   `Text' is defined by ISO 8859.
  52. X   diff3 exit status 0 means success, 1 means overlaps, 2 means trouble.
  53. X
  54. XThis version of diff provides all the features of BSD's diff.
  55. XIt has these additional features:
  56. X
  57. X   An input file may end in a non-newline character.  If so, its last
  58. X   line is called an incomplete line and is distinguished on output
  59. X   from a full line.  In the default, -c, and -u output styles, an
  60. X   incomplete output line is followed by a diagnostic line that starts
  61. X   with \.  With -n, an incomplete line is output without a trailing
  62. X   newline.  Other output styles (-D, -e, -f) cannot represent an
  63. X   incomplete line, so they pretend that there was a newline, and -e and -f
  64. X   also print an error message.  For example, suppose F and G are one-byte
  65. X   files that contain just ``f'' and ``g'', respectively.
  66. X
  67. X   Then ``diff F G'' outputs
  68. X
  69. X    1c1
  70. X    < f
  71. X    \ No newline at end of file
  72. X    ---
  73. X    > g
  74. X    \ No newline at end of file
  75. X
  76. X   (The exact diagnostic message may differ, e.g. for non-English locales.)
  77. X   ``diff -n F G'' outputs the following without a trailing newline:
  78. X
  79. X    d1 1
  80. X    a1 1
  81. X    g
  82. X
  83. X   ``diff -e F G'' sends two diagnostics to stderr and the following to stdout:
  84. X
  85. X    1c
  86. X    g
  87. X    .
  88. X
  89. X   A file is considered to be text if its first characters are all in the
  90. X   ISO 8859 character set; BSD's diff uses Ascii.
  91. X
  92. X   GNU DIFF has the following additional options:
  93. X
  94. X   -a    Always treat files as text and compare them line-by-line,
  95. X    even if they do not appear to be text.
  96. X
  97. X   -B    ignore changes that just insert or delete blank lines.
  98. X
  99. X   -C #
  100. X    request -c format and specify number of context lines.
  101. X
  102. X   -F regexp
  103. X    in context format, for each unit of differences, show some of
  104. X    the last preceding line that matches the specified regexp.
  105. X
  106. X   -H    use heuristics to speed handling of large files that
  107. X    have numerous scattered small changes.  The algorithm becomes
  108. X        asymptotically linear for such files!
  109. X    
  110. X   -I regexp
  111. X    ignore changes that just insert or delete lines that
  112. X    match the specified regexp.
  113. X
  114. X   -L label
  115. X    Use the specified label in file header lines output by the -c option.
  116. X    This option may be given zero, one, or two times,
  117. X    to affect neither label, just the first file's label, or both labels.
  118. X    A file's default label is its name, a tab, and its modification date.
  119. X
  120. X   -N    in directory comparison, if a file is found in only one directory,
  121. X    treat it as present but empty in the other directory.
  122. X
  123. X   -p    equivalent to -c -F'^[_a-zA-Z]'.  This is useful for C code
  124. X    because it shows which function each change is in.
  125. X
  126. X   -T    print a tab rather than a space before the text of a line
  127. X    in normal or context format.  This causes the alignment
  128. X    of tabs in the line to look normal.
  129. X
  130. X   -u[#]
  131. X    produce unified style output with # context lines (default 3).
  132. X    This style is like -c, but it is more compact because context
  133. X    lines are printed only once.  Lines from just the first file
  134. X    are marked '-'; lines from just the second file are marked '+'.
  135. X
  136. XThis version of diff3 has all of BSD diff3's features, with the following
  137. Xadditional features.
  138. X
  139. X   An input file may end in a non-newline character.  With the -m option,
  140. X   an incomplete last line stays incomplete.  Other output styles treat
  141. X   incomplete lines like diff.
  142. X
  143. X   The file name '-' denotes the standard input.  It can appear at most once.
  144. X
  145. X   diff3 has the following additional options:
  146. X
  147. X   -a    Always treat files as text and compare them line-by-line,
  148. X    even if they do not appear to be text.
  149. X
  150. X   -i    Include 'w' and 'q' commands at the end of the output, to write out
  151. X    the changed file, thus emulating system V behavior.  One of the edit
  152. X    script options -e, -E, -x, -X, -3 must also be specified.
  153. X
  154. X   -m    Apply the edit script to the first file and send the result to
  155. X    standard output.  Unlike piping diff3's output to ed(1), this works
  156. X    even for binary files and incomplete lines.  -E is assumed if no edit
  157. X    script option is specified.  This option is incompatible with -i.
  158. X
  159. X   -L label
  160. X    Use the specified label for lines output by the -E and -X options,
  161. X    one of which must also be specified.  This option may be given zero,
  162. X    one, or two times; the first label marks <<<<<<< lines and the second
  163. X    marks >>>>>>> lines.  The default labels are the names of the first and
  164. X    third files on the command line.  Thus ``diff3 -L X -L Z -E A B C''
  165. X    acts like ``diff3 -E A B C'', except that the output looks like it
  166. X    came from files named X and Z rather than from files named A and C.
  167. X
  168. X    Exit status 0 means success, 1 means overlaps were found and -E or -X was
  169. X    specified, and 2 means trouble.
  170. X
  171. X
  172. X
  173. XGNU DIFF was written by Mike Haertel, David Hayes, Richard Stallman
  174. Xand Len Tower.  The basic algorithm is described in: "An O(ND)
  175. XDifference Algorithm and its Variations", Eugene Myers, Algorithmica
  176. XVol. 1 No. 2, 1986, p 251.
  177. X
  178. XMany bugs were fixed by Paul Eggert.  The unified diff idea and format
  179. Xare from Wayne Davison.
  180. X
  181. XSuggested projects for improving GNU DIFF:
  182. X
  183. X* Handle very large files by not keeping the entire text in core.
  184. X
  185. XOne way to do this is to scan the files sequentally to compute hash
  186. Xcodes of the lines and put the lines in equivalence classes based only
  187. Xon hash code.  Then compare the files normally.  This will produce
  188. Xsome false matches.
  189. X
  190. XThen scan the two files sequentially again, checking each match to see
  191. Xwhether it is real.  When a match is not real, mark both the
  192. X"matching" lines as changed.  Then build an edit script as usual.
  193. X
  194. XThe output routines would have to be changed to scan the files
  195. Xsequentially looking for the text to print.
  196. END_OF_FILE
  197. if test 5997 -ne `wc -c <'README'`; then
  198.     echo shar: \"'README'\" unpacked with wrong size!
  199. fi
  200. # end of 'README'
  201. fi
  202. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  203.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  204. else
  205. echo shar: Extracting \"'MANIFEST'\" \(1734 characters\)
  206. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  207. X   File Name        Archive #    Description
  208. X-----------------------------------------------------------
  209. X COPYING                    2    copying permissions (GNU General Public License)
  210. X ChangeLog                  4    log of recent changes
  211. X MANIFEST                   1    This shipping list
  212. X Makefile                   1    makefile for GNU DIFF
  213. X README                     1    Read me first.
  214. X alloca.c                   1    Gwyn's (mostly) portable public-domain alloca()
  215. X analyze.c                  5    Analyze file differences for GNU DIFF.
  216. X context.c                  2    context-format output routines for GNU DIFF
  217. X diagmeet.note              1    an internals note on how diff diagonals meet
  218. X diff.c                     3    GNU DIFF main routine
  219. X diff.h                     2    shared definitions for GNU DIFF
  220. X diff3.c                    8    three-way file comparison program (diff3)
  221. X dir.c                      1    Read, sort and compare two directories.
  222. X ed.c                       1    output routines for ed-script format
  223. X getopt.c                   3    getopt for GNU
  224. X getopt.h                   1    declarations for getopt
  225. X getopt1.c                  1    (long) getopt for GNU
  226. X ifdef.c                    1    #ifdef-format output routines for GNU DIFF
  227. X io.c                       4    file I/O for GNU DIFF
  228. X limits.h                   1    implementation limits
  229. X normal.c                   1    normal-format output routines for GNU DIFF
  230. X regex.c1                   7    regular expression matching and search (part 1)
  231. X regex.c2                   6    regular expression matching and search (part 2)
  232. X regex.h                    2    definitions for regex data structures
  233. X util.c                     3    support routines for GNU DIFF
  234. X version.c                  1    version number of GNU DIFF
  235. END_OF_FILE
  236. if test 1734 -ne `wc -c <'MANIFEST'`; then
  237.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  238. fi
  239. # end of 'MANIFEST'
  240. fi
  241. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  242.   echo shar: Will not clobber existing file \"'Makefile'\"
  243. else
  244. echo shar: Extracting \"'Makefile'\" \(3536 characters\)
  245. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  246. X# Makefile for GNU DIFF
  247. X# Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  248. X
  249. X# This file is part of GNU DIFF.
  250. X
  251. X# GNU DIFF is free software; you can redistribute it and/or modify
  252. X# it under the terms of the GNU General Public License as published by
  253. X# the Free Software Foundation; either version 1, or (at your option)
  254. X# any later version.
  255. X# 
  256. X# GNU DIFF is distributed in the hope that it will be useful,
  257. X# but WITHOUT ANY WARRANTY; without even the implied warranty of
  258. X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  259. X# GNU General Public License for more details.
  260. X# 
  261. X# You should have received a copy of the GNU General Public License
  262. X# along with GNU DIFF; see the file COPYING.  If not, write to
  263. X# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  264. X
  265. X# You can compile this with ordinary cc as well,
  266. X# but gcc makes it faster.
  267. X# Also, gcc supports -O and -g together.
  268. XCC=gcc -O
  269. XCFLAGS = -g
  270. XINSTALL = install
  271. X
  272. X# On system V, enable these three lines:
  273. X# CFLAGS = -g -DUSG
  274. X# LIBS = -lPW
  275. X# INSTALL = cp
  276. X# (If you compile with GCC, you don't need to define LIBS.)
  277. X# And, depending on the names and contents of your header files,
  278. X# add either -DHAVE_NDIR or -DHAVE_DIRECT or both to CFLAGS.
  279. X# Add -DHAVE_NDIR to CFLAGS if your system used ndir.h instead of dirent.h
  280. X# Add -DHAVE_DIRECT to CFLAGS if your system uses 'struct direct' instead of
  281. X# 'struct dirent' (this is the case at least with one add-on ndir library).
  282. X
  283. X# Use these definitions for XENIX:
  284. X# There are rumors of bugs in various Xenix's dirent.h and -ldir.  As
  285. X# a result, we suggest using HAVE_NDIR and not using -ldir.
  286. X# CFLAGS = -O -DUSG -DXENIX -DHAVE_NDIR -DHAVE_DIRECT -DNDIR_IN_SYS
  287. X# LIBS = -lx -lPW
  288. X# INSTALL = cp
  289. X
  290. X# Some System V machines do not come with libPW.  If this is true, use
  291. X# the GNU alloca by switching the comment on the following lines.
  292. XALLOCA = 
  293. X# ALLOCA = $(archpfx)/alloca.o
  294. X
  295. Xbindir=/usr/local/bin
  296. Xprefix=
  297. X
  298. X# All source files
  299. Xsrcs=diff.c analyze.c io.c context.c ed.c normal.c ifdef.c util.c dir.c \
  300. X    version.c diff.h regex.c regex.h limits.h diff3.c \
  301. X    getopt.c getopt1.c getopt.h alloca.c
  302. X# Object files for diff only.
  303. Xobjs=$(archpfx)diff.o $(archpfx)analyze.o $(archpfx)io.o $(archpfx)context.o \
  304. X     $(archpfx)ed.o $(archpfx)normal.o $(archpfx)util.o $(archpfx)dir.o \
  305. X     $(archpfx)regex.o $(archpfx)ifdef.o $(archpfx)version.o \
  306. X     $(archpfx)getopt.o $(archpfx)getopt1.o
  307. Xtapefiles = $(srcs) README diagmeet.note Makefile COPYING ChangeLog
  308. X
  309. Xall: $(archpfx)diff $(archpfx)diff3
  310. X
  311. X$(archpfx)diff3: $(archpfx)diff3.o
  312. X    $(CC) -o $(archpfx)diff3 $(CFLAGS) $(LDFLAGS) $(archpfx)diff3.o $(LIBS)
  313. X
  314. X$(archpfx)diff: $(objs)
  315. X    $(CC) -o $(archpfx)diff $(CFLAGS) $(LDFLAGS) $(objs) $(LIBS)
  316. X
  317. X$(objs): diff.h
  318. X
  319. X$(archpfx)context.o $(archpfx)diff.o: regex.h
  320. X
  321. X$(archpfx)diff3.o: diff3.c
  322. X    $(CC) -c $(CFLAGS) -DDIFF_PROGRAM=\"$(bindir)/diff\" diff3.c \
  323. X $(OUTPUT_OPTION)
  324. X
  325. Xclean:
  326. X    rm -f *.o $(archpfx)diff $(archpfx)diff3 diff.tar diff.tar.Z
  327. X
  328. Xinstall: install-diff install-diff3
  329. X
  330. Xinstall-diff: $(prefix)$(bindir)/diff
  331. X
  332. X$(prefix)$(bindir)/diff: $(archpfx)diff
  333. X    $(INSTALL) $(archpfx)diff $(prefix)$(bindir)/diff
  334. X
  335. Xinstall-diff3: $(prefix)$(bindir)/diff3
  336. X
  337. X$(prefix)$(bindir)/diff3: $(archpfx)diff3
  338. X    $(INSTALL) $(archpfx)diff3 $(prefix)$(bindir)/diff3
  339. X
  340. Xdiff.tar: $(tapefiles)
  341. X    mkdir tmp
  342. X    mkdir tmp/diff
  343. X    -ln $(tapefiles) tmp/diff
  344. X    for file in $(tapefiles); do \
  345. X        if [ ! -r tmp/diff/$$file ]; then cp $$file tmp/diff; fi \
  346. X    done
  347. X    cd tmp; tar cf ../diff.tar diff
  348. X    rm -rf tmp
  349. X
  350. Xdiff.tar.Z: diff.tar
  351. X    compress < diff.tar > diff.tar.Z
  352. END_OF_FILE
  353. if test 3536 -ne `wc -c <'Makefile'`; then
  354.     echo shar: \"'Makefile'\" unpacked with wrong size!
  355. fi
  356. # end of 'Makefile'
  357. fi
  358. if test -f 'alloca.c' -a "${1}" != "-c" ; then 
  359.   echo shar: Will not clobber existing file \"'alloca.c'\"
  360. else
  361. echo shar: Extracting \"'alloca.c'\" \(5214 characters\)
  362. sed "s/^X//" >'alloca.c' <<'END_OF_FILE'
  363. X/*
  364. X    alloca -- (mostly) portable public-domain implementation -- D A Gwyn
  365. X
  366. X    last edit:    86/05/30    rms
  367. X       include config.h, since on VMS it renames some symbols.
  368. X       Use xmalloc instead of malloc.
  369. X
  370. X    This implementation of the PWB library alloca() function,
  371. X    which is used to allocate space off the run-time stack so
  372. X    that it is automatically reclaimed upon procedure exit, 
  373. X    was inspired by discussions with J. Q. Johnson of Cornell.
  374. X
  375. X    It should work under any C implementation that uses an
  376. X    actual procedure stack (as opposed to a linked list of
  377. X    frames).  There are some preprocessor constants that can
  378. X    be defined when compiling for your specific system, for
  379. X    improved efficiency; however, the defaults should be okay.
  380. X
  381. X    The general concept of this implementation is to keep
  382. X    track of all alloca()-allocated blocks, and reclaim any
  383. X    that are found to be deeper in the stack than the current
  384. X    invocation.  This heuristic does not reclaim storage as
  385. X    soon as it becomes invalid, but it will do so eventually.
  386. X
  387. X    As a special case, alloca(0) reclaims storage without
  388. X    allocating any.  It is a good idea to use alloca(0) in
  389. X    your main control loop, etc. to force garbage collection.
  390. X*/
  391. X#ifndef lint
  392. Xstatic char    SCCSid[] = "@(#)alloca.c    1.1";    /* for the "what" utility */
  393. X#endif
  394. X
  395. X#ifdef emacs
  396. X#include "config.h"
  397. X#ifdef static
  398. X/* actually, only want this if static is defined as ""
  399. X   -- this is for usg, in which emacs must undefine static
  400. X   in order to make unexec workable
  401. X   */
  402. X#ifndef STACK_DIRECTION
  403. Xyou
  404. Xlose
  405. X-- must know STACK_DIRECTION at compile-time
  406. X#endif /* STACK_DIRECTION undefined */
  407. X#endif static
  408. X#endif emacs
  409. X
  410. X#ifdef X3J11
  411. Xtypedef void    *pointer;        /* generic pointer type */
  412. X#else
  413. Xtypedef char    *pointer;        /* generic pointer type */
  414. X#endif
  415. X
  416. X#define    NULL    0            /* null pointer constant */
  417. X
  418. Xextern void    free();
  419. Xextern pointer    xmalloc();
  420. X
  421. X/*
  422. X    Define STACK_DIRECTION if you know the direction of stack
  423. X    growth for your system; otherwise it will be automatically
  424. X    deduced at run-time.
  425. X
  426. X    STACK_DIRECTION > 0 => grows toward higher addresses
  427. X    STACK_DIRECTION < 0 => grows toward lower addresses
  428. X    STACK_DIRECTION = 0 => direction of growth unknown
  429. X*/
  430. X
  431. X#ifndef STACK_DIRECTION
  432. X#define    STACK_DIRECTION    0        /* direction unknown */
  433. X#endif
  434. X
  435. X#if STACK_DIRECTION != 0
  436. X
  437. X#define    STACK_DIR    STACK_DIRECTION    /* known at compile-time */
  438. X
  439. X#else    /* STACK_DIRECTION == 0; need run-time code */
  440. X
  441. Xstatic int    stack_dir;        /* 1 or -1 once known */
  442. X#define    STACK_DIR    stack_dir
  443. X
  444. Xstatic void
  445. Xfind_stack_direction (/* void */)
  446. X{
  447. X  static char    *addr = NULL;    /* address of first
  448. X                   `dummy', once known */
  449. X  auto char    dummy;        /* to get stack address */
  450. X
  451. X  if (addr == NULL)
  452. X    {                /* initial entry */
  453. X      addr = &dummy;
  454. X
  455. X      find_stack_direction ();    /* recurse once */
  456. X    }
  457. X  else                /* second entry */
  458. X    if (&dummy > addr)
  459. X      stack_dir = 1;        /* stack grew upward */
  460. X    else
  461. X      stack_dir = -1;        /* stack grew downward */
  462. X}
  463. X
  464. X#endif    /* STACK_DIRECTION == 0 */
  465. X
  466. X/*
  467. X    An "alloca header" is used to:
  468. X    (a) chain together all alloca()ed blocks;
  469. X    (b) keep track of stack depth.
  470. X
  471. X    It is very important that sizeof(header) agree with malloc()
  472. X    alignment chunk size.  The following default should work okay.
  473. X*/
  474. X
  475. X#ifndef    ALIGN_SIZE
  476. X#define    ALIGN_SIZE    sizeof(double)
  477. X#endif
  478. X
  479. Xtypedef union hdr
  480. X{
  481. X  char    align[ALIGN_SIZE];    /* to force sizeof(header) */
  482. X  struct
  483. X    {
  484. X      union hdr *next;        /* for chaining headers */
  485. X      char *deep;        /* for stack depth measure */
  486. X    } h;
  487. X} header;
  488. X
  489. X/*
  490. X    alloca( size ) returns a pointer to at least `size' bytes of
  491. X    storage which will be automatically reclaimed upon exit from
  492. X    the procedure that called alloca().  Originally, this space
  493. X    was supposed to be taken from the current stack frame of the
  494. X    caller, but that method cannot be made to work for some
  495. X    implementations of C, for example under Gould's UTX/32.
  496. X*/
  497. X
  498. Xstatic header *last_alloca_header = NULL; /* -> last alloca header */
  499. X
  500. Xpointer
  501. Xalloca (size)            /* returns pointer to storage */
  502. X     unsigned    size;        /* # bytes to allocate */
  503. X{
  504. X  auto char    probe;        /* probes stack depth: */
  505. X  register char    *depth = &probe;
  506. X
  507. X#if STACK_DIRECTION == 0
  508. X  if (STACK_DIR == 0)        /* unknown growth direction */
  509. X    find_stack_direction ();
  510. X#endif
  511. X
  512. X                /* Reclaim garbage, defined as all alloca()ed storage that
  513. X                   was allocated from deeper in the stack than currently. */
  514. X
  515. X  {
  516. X    register header    *hp;    /* traverses linked list */
  517. X
  518. X    for (hp = last_alloca_header; hp != NULL;)
  519. X      if (STACK_DIR > 0 && hp->h.deep > depth
  520. X      || STACK_DIR < 0 && hp->h.deep < depth)
  521. X    {
  522. X      register header    *np = hp->h.next;
  523. X
  524. X      free ((pointer) hp);    /* collect garbage */
  525. X
  526. X      hp = np;        /* -> next header */
  527. X    }
  528. X      else
  529. X    break;            /* rest are not deeper */
  530. X
  531. X    last_alloca_header = hp;    /* -> last valid storage */
  532. X  }
  533. X
  534. X  if (size == 0)
  535. X    return NULL;        /* no allocation required */
  536. X
  537. X  /* Allocate combined header + user data storage. */
  538. X
  539. X  {
  540. X    register pointer    new = xmalloc (sizeof (header) + size);
  541. X    /* address of header */
  542. X
  543. X    ((header *)new)->h.next = last_alloca_header;
  544. X    ((header *)new)->h.deep = depth;
  545. X
  546. X    last_alloca_header = (header *)new;
  547. X
  548. X    /* User storage begins just after header. */
  549. X
  550. X    return (pointer)((char *)new + sizeof(header));
  551. X  }
  552. X}
  553. X
  554. END_OF_FILE
  555. if test 5214 -ne `wc -c <'alloca.c'`; then
  556.     echo shar: \"'alloca.c'\" unpacked with wrong size!
  557. fi
  558. # end of 'alloca.c'
  559. fi
  560. if test -f 'diagmeet.note' -a "${1}" != "-c" ; then 
  561.   echo shar: Will not clobber existing file \"'diagmeet.note'\"
  562. else
  563. echo shar: Extracting \"'diagmeet.note'\" \(1069 characters\)
  564. sed "s/^X//" >'diagmeet.note' <<'END_OF_FILE'
  565. XHere is a comparison matrix which shows a case in which
  566. Xit is possible for the forward and backward scan in `diag'
  567. Xto meet along a nonzero length of diagonal simultaneous
  568. X(so that bdiag[d] and fdiag[d] are not equal)
  569. Xeven though there is no snake on that diagonal at the meeting point.
  570. X
  571. X
  572. X     85   1   1   1  159  1   1   17
  573. X        1   2   3   4
  574. X60
  575. X    1   2
  576. X1
  577. X    2          2   3   4
  578. X71
  579. X    3       3      4   5
  580. X85
  581. X    4      3   4    5
  582. X17
  583. X    5      4   5
  584. X1
  585. X    6       4      5   6
  586. X183
  587. X    7       5   6   7
  588. X10
  589. X    8          6      7
  590. X1
  591. X    9           6   7      8
  592. X12
  593. X                7   8   9  10
  594. X13
  595. X       10       8   9  10
  596. X14
  597. X           10   9  10
  598. X17
  599. X       10      10
  600. X1
  601. X   10   9  10
  602. X1
  603. X    8      10      10      10
  604. X183
  605. X    8   7    9       9          9
  606. X10
  607. X    7   6    8   9   8          8
  608. X1
  609. X    6   5            7       7
  610. X1
  611. X            5              6          6
  612. X1
  613. X               5          5          5
  614. X50
  615. X        5   4          4          4
  616. X1
  617. X                4   3    3
  618. X85
  619. X        5   4   3   2       2
  620. X1
  621. X                        2   1
  622. X17
  623. X        5   4   3   2   1       1
  624. X1
  625. X                        1   0
  626. X     85   1   1   1  159  1   1  17
  627. X
  628. X
  629. X
  630. X
  631. X
  632. X
  633. X
  634. X
  635. X
  636. END_OF_FILE
  637. if test 1069 -ne `wc -c <'diagmeet.note'`; then
  638.     echo shar: \"'diagmeet.note'\" unpacked with wrong size!
  639. fi
  640. # end of 'diagmeet.note'
  641. fi
  642. if test -f 'dir.c' -a "${1}" != "-c" ; then 
  643.   echo shar: Will not clobber existing file \"'dir.c'\"
  644. else
  645. echo shar: Extracting \"'dir.c'\" \(5765 characters\)
  646. sed "s/^X//" >'dir.c' <<'END_OF_FILE'
  647. X/* Read, sort and compare two directories.  Used for GNU DIFF.
  648. X   Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  649. X
  650. XThis file is part of GNU DIFF.
  651. X
  652. XGNU DIFF is free software; you can redistribute it and/or modify
  653. Xit under the terms of the GNU General Public License as published by
  654. Xthe Free Software Foundation; either version 1, or (at your option)
  655. Xany later version.
  656. X
  657. XGNU DIFF is distributed in the hope that it will be useful,
  658. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  659. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  660. XGNU General Public License for more details.
  661. X
  662. XYou should have received a copy of the GNU General Public License
  663. Xalong with GNU DIFF; see the file COPYING.  If not, write to
  664. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  665. X
  666. X#include "diff.h"
  667. X
  668. Xstatic int compare_names ();
  669. X
  670. X/* Read the directory named DIRNAME and return a sorted vector
  671. X   of filenames for its contents.  NONEX nonzero means this directory is
  672. X   known to be nonexistent, so return zero files.  */
  673. X
  674. Xstruct dirdata
  675. X{
  676. X  int length;            /* # elements in `files' */
  677. X  char **files;            /* Sorted names of files in the dir */
  678. X};
  679. X
  680. Xstatic struct dirdata
  681. Xdir_sort (dirname, nonex)
  682. X     char *dirname;
  683. X     int nonex;
  684. X{
  685. X  register DIR *reading;
  686. X  register struct direct *next;
  687. X  struct dirdata dirdata;
  688. X
  689. X  /* Address of block containing the files that are described.  */
  690. X  char **files;
  691. X
  692. X  /* Length of block that `files' points to, measured in files.  */
  693. X  int nfiles;
  694. X
  695. X  /* Index of first unused in `files'.  */
  696. X  int files_index;
  697. X
  698. X  if (nonex)
  699. X    {
  700. X      dirdata.length = 0;
  701. X      dirdata.files = 0;
  702. X      return dirdata;
  703. X    }
  704. X
  705. X  /* Open the directory and check for errors.  */
  706. X  reading = opendir (dirname);
  707. X  if (!reading)
  708. X    {
  709. X      perror_with_name (dirname);
  710. X      dirdata.length = -1;
  711. X      return dirdata;
  712. X    }
  713. X
  714. X  /* Initialize the table of filenames.  */
  715. X
  716. X  nfiles = 100;
  717. X  files = (char **) xmalloc (nfiles * sizeof (char *));
  718. X  files_index = 0;
  719. X
  720. X  /* Read the directory entries, and insert the subfiles
  721. X     into the `files' table.  */
  722. X
  723. X  while (next = readdir (reading))
  724. X    {
  725. X      /* Ignore the files `.' and `..' */
  726. X      if (next->d_name[0] == '.'
  727. X      && (next->d_name[1] == 0
  728. X          || (next->d_name[1] == '.'
  729. X          && next->d_name[2] == 0)))
  730. X    continue;
  731. X
  732. X      if (files_index == nfiles)
  733. X    {
  734. X      nfiles *= 2;
  735. X      files
  736. X        = (char **) xrealloc (files, sizeof (char *) * nfiles);
  737. X    }
  738. X      files[files_index++] = concat (next->d_name, "", "");
  739. X    }
  740. X
  741. X  closedir (reading);
  742. X
  743. X  /* Sort the table.  */
  744. X  qsort (files, files_index, sizeof (char *), compare_names);
  745. X
  746. X  /* Return a description of location and length of the table.  */
  747. X  dirdata.files = files;
  748. X  dirdata.length = files_index;
  749. X
  750. X  return dirdata;
  751. X}
  752. X
  753. X/* Sort the files now in the table.  */
  754. X
  755. Xstatic int
  756. Xcompare_names (file1, file2)
  757. X     char **file1, **file2;
  758. X{
  759. X  return strcmp (*file1, *file2);
  760. X}
  761. X
  762. X/* Compare the contents of two directories named NAME1 and NAME2.
  763. X   This is a top-level routine; it does everything necessary for diff
  764. X   on two directories.
  765. X
  766. X   NONEX1 nonzero says directory NAME1 doesn't exist, but pretend it is
  767. X   empty.  Likewise NONEX2.
  768. X
  769. X   HANDLE_FILE is a caller-provided subroutine called to handle each file.
  770. X   It gets five operands: dir and name (rel to original working dir) of file
  771. X   in dir 1, dir and name pathname of file in dir 2, and the recursion depth.
  772. X
  773. X   For a file that appears in only one of the dirs, one of the name-args
  774. X   to HANDLE_FILE is zero.
  775. X
  776. X   DEPTH is the current depth in recursion.
  777. X
  778. X   Returns the maximum of all the values returned by HANDLE_FILE,
  779. X   or 2 if trouble is encountered in opening files.  */
  780. X
  781. Xint
  782. Xdiff_dirs (name1, name2, handle_file, depth, nonex1, nonex2)
  783. X     char *name1, *name2;
  784. X     int (*handle_file) ();
  785. X     int nonex1, nonex2;
  786. X{
  787. X  struct dirdata data1, data2;
  788. X  register int i1, i2;
  789. X  int val = 0;
  790. X  int v1;
  791. X
  792. X  /* Get sorted contents of both dirs.  */
  793. X  data1 = dir_sort (name1, nonex1);
  794. X  data2 = dir_sort (name2, nonex2);
  795. X  if (data1.length == -1 || data2.length == -1)
  796. X    {
  797. X      if (data1.length >= 0)
  798. X    free (data1.files);
  799. X      if (data2.length >= 0)
  800. X    free (data2.files);
  801. X      return 2;
  802. X    }
  803. X
  804. X  i1 = 0;
  805. X  i2 = 0;
  806. X
  807. X  /* If -Sname was specified, and this is the topmost level of comparison,
  808. X     ignore all file names less than the specified starting name.  */
  809. X
  810. X  if (dir_start_file && depth == 0)
  811. X    {
  812. X      while (i1 < data1.length && strcmp (data1.files[i1], dir_start_file) < 0)
  813. X    i1++;
  814. X      while (i2 < data2.length && strcmp (data2.files[i2], dir_start_file) < 0)
  815. X    i2++;
  816. X    }
  817. X
  818. X  /* Loop while files remain in one or both dirs.  */
  819. X  while (i1 < data1.length || i2 < data2.length)
  820. X    {
  821. X      int nameorder;
  822. X
  823. X      /* Compare next name in dir 1 with next name in dir 2.
  824. X     At the end of a dir,
  825. X     pretend the "next name" in that dir is very large.  */
  826. X
  827. X      if (i1 == data1.length)
  828. X    nameorder = 1;
  829. X      else if (i2 == data2.length)
  830. X    nameorder = -1;
  831. X      else
  832. X    nameorder = strcmp (data1.files[i1], data2.files[i2]);
  833. X
  834. X      if (nameorder == 0)
  835. X    {
  836. X      /* We have found a file (or subdir) in common between both dirs.
  837. X         Compare the two files.  */
  838. X      v1 = (*handle_file) (name1, data1.files[i1], name2, data2.files[i2],
  839. X                   depth + 1);
  840. X      i1++, i2++;
  841. X    }
  842. X      if (nameorder < 0)
  843. X    {
  844. X      /* Next filename in dir 1 is less; that is a file in dir 1 only.  */
  845. X      v1 = (*handle_file) (name1, data1.files[i1], name2, 0, depth + 1);
  846. X      i1++;
  847. X    }
  848. X      if (nameorder > 0)
  849. X    {
  850. X      /* Next filename in dir 2 is less; that is a file in dir 2 only.  */
  851. X      v1 = (*handle_file) (name1, 0, name2, data2.files[i2], depth + 1);
  852. X      i2++;
  853. X    }
  854. X      if (v1 > val)
  855. X    val = v1;
  856. X    }
  857. X  if (data1.files)
  858. X    free (data1.files);
  859. X  if (data2.files)
  860. X    free (data2.files);
  861. X
  862. X  return val;
  863. X}
  864. END_OF_FILE
  865. if test 5765 -ne `wc -c <'dir.c'`; then
  866.     echo shar: \"'dir.c'\" unpacked with wrong size!
  867. fi
  868. # end of 'dir.c'
  869. fi
  870. if test -f 'ed.c' -a "${1}" != "-c" ; then 
  871.   echo shar: Will not clobber existing file \"'ed.c'\"
  872. else
  873. echo shar: Extracting \"'ed.c'\" \(5254 characters\)
  874. sed "s/^X//" >'ed.c' <<'END_OF_FILE'
  875. X/* Output routines for ed-script format.
  876. X   Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  877. X
  878. XThis file is part of GNU DIFF.
  879. X
  880. XGNU DIFF is free software; you can redistribute it and/or modify
  881. Xit under the terms of the GNU General Public License as published by
  882. Xthe Free Software Foundation; either version 1, or (at your option)
  883. Xany later version.
  884. X
  885. XGNU DIFF is distributed in the hope that it will be useful,
  886. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  887. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  888. XGNU General Public License for more details.
  889. X
  890. XYou should have received a copy of the GNU General Public License
  891. Xalong with GNU DIFF; see the file COPYING.  If not, write to
  892. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  893. X
  894. X#include "diff.h"
  895. X
  896. Xstatic void print_rcs_hunk ();
  897. Xstatic void print_ed_hunk ();
  898. Xstatic void pr_forward_ed_hunk ();
  899. Xvoid translate_range ();
  900. Xstruct change *find_change ();
  901. Xstruct change *find_reverse_change ();
  902. X
  903. X/* Print our script as ed commands.  */
  904. X
  905. Xvoid
  906. Xprint_ed_script (script)
  907. X    struct change *script;
  908. X{
  909. X  print_script (script, find_reverse_change, print_ed_hunk);
  910. X}
  911. X
  912. X/* Print a hunk of an ed diff */
  913. X
  914. Xstatic void
  915. Xprint_ed_hunk (hunk)
  916. X     struct change *hunk; 
  917. X{
  918. X  int f0, l0, f1, l1;
  919. X  int deletes, inserts;
  920. X
  921. X#if 0
  922. X  hunk = flip_script (hunk);
  923. X#endif
  924. X#ifdef DEBUG
  925. X  debug_script (hunk);
  926. X#endif
  927. X
  928. X  /* Determine range of line numbers involved in each file.  */
  929. X  analyze_hunk (hunk, &f0, &l0, &f1, &l1, &deletes, &inserts);
  930. X  if (!deletes && !inserts)
  931. X    return;
  932. X
  933. X  /* Print out the line number header for this hunk */
  934. X  print_number_range (',', &files[0], f0, l0);
  935. X  fprintf (outfile, "%c\n", change_letter (inserts, deletes));
  936. X
  937. X  /* Print new/changed lines from second file, if needed */
  938. X  if (inserts)
  939. X    {
  940. X      int i;
  941. X      int inserting = 1;
  942. X      for (i = f1; i <= l1; i++)
  943. X    {
  944. X      /* Resume the insert, if we stopped.  */
  945. X      if (! inserting)
  946. X        fprintf (outfile, "%da\n",
  947. X             i - f1 + translate_line_number (&files[0], f0) - 1);
  948. X      inserting = 1;
  949. X
  950. X      /* If the file's line is just a dot, it would confuse `ed'.
  951. X         So output it with a double dot, and set the flag LEADING_DOT
  952. X         so that we will output another ed-command later
  953. X         to change the double dot into a single dot.  */
  954. X
  955. X      if (files[1].linbuf[i].text[0] == '.'
  956. X          && files[1].linbuf[i].text[1] == '\n')
  957. X        {
  958. X          fprintf (outfile, "..\n");
  959. X          fprintf (outfile, ".\n");
  960. X          /* Now change that double dot to the desired single dot.  */
  961. X          fprintf (outfile, "%ds/^\\.\\././\n",
  962. X               i - f1 + translate_line_number (&files[0], f0));
  963. X          inserting = 0;
  964. X        }
  965. X      else
  966. X        /* Line is not `.', so output it unmodified.  */
  967. X        print_1_line ("", &files[1].linbuf[i]);
  968. X    }
  969. X
  970. X      /* End insert mode, if we are still in it.  */
  971. X      if (inserting)
  972. X    fprintf (outfile, ".\n");
  973. X    }
  974. X}
  975. X
  976. X/* Print change script in the style of ed commands,
  977. X   but print the changes in the order they appear in the input files,
  978. X   which means that the commands are not truly useful with ed.  */
  979. X
  980. Xvoid
  981. Xpr_forward_ed_script (script)
  982. X     struct change *script;
  983. X{
  984. X  print_script (script, find_change, pr_forward_ed_hunk);
  985. X}
  986. X
  987. Xstatic void
  988. Xpr_forward_ed_hunk (hunk)
  989. X     struct change *hunk;
  990. X{
  991. X  int i;
  992. X  int f0, l0, f1, l1;
  993. X  int deletes, inserts;
  994. X
  995. X  /* Determine range of line numbers involved in each file.  */
  996. X  analyze_hunk (hunk, &f0, &l0, &f1, &l1, &deletes, &inserts);
  997. X  if (!deletes && !inserts)
  998. X    return;
  999. X
  1000. X  fprintf (outfile, "%c", change_letter (inserts, deletes));
  1001. X  print_number_range (' ', files, f0, l0);
  1002. X  fprintf (outfile, "\n");
  1003. X
  1004. X  /* If deletion only, print just the number range.  */
  1005. X
  1006. X  if (!inserts)
  1007. X    return;
  1008. X
  1009. X  /* For insertion (with or without deletion), print the number range
  1010. X     and the lines from file 2.  */
  1011. X
  1012. X  for (i = f1; i <= l1; i++)
  1013. X    print_1_line ("", &files[1].linbuf[i]);
  1014. X
  1015. X  fprintf (outfile, ".\n");
  1016. X}
  1017. X
  1018. X/* Print in a format somewhat like ed commands
  1019. X   except that each insert command states the number of lines it inserts.
  1020. X   This format is used for RCS.  */
  1021. X
  1022. Xvoid
  1023. Xprint_rcs_script (script)
  1024. X     struct change *script;
  1025. X{
  1026. X  print_script (script, find_change, print_rcs_hunk);
  1027. X}
  1028. X
  1029. X/* Print a hunk of an RCS diff */
  1030. X
  1031. Xstatic void
  1032. Xprint_rcs_hunk (hunk)
  1033. X     struct change *hunk;
  1034. X{
  1035. X  int i;
  1036. X  int f0, l0, f1, l1;
  1037. X  int deletes, inserts;
  1038. X  int tf0, tl0, tf1, tl1;
  1039. X
  1040. X  /* Determine range of line numbers involved in each file.  */
  1041. X  analyze_hunk (hunk, &f0, &l0, &f1, &l1, &deletes, &inserts);
  1042. X  if (!deletes && !inserts)
  1043. X    return;
  1044. X
  1045. X  translate_range (&files[0], f0, l0, &tf0, &tl0);
  1046. X
  1047. X  if (deletes)
  1048. X    {
  1049. X      fprintf (outfile, "d");
  1050. X      /* For deletion, print just the starting line number from file 0
  1051. X     and the number of lines deleted.  */
  1052. X      fprintf (outfile, "%d %d\n",
  1053. X           tf0,
  1054. X           (tl0 >= tf0 ? tl0 - tf0 + 1 : 1));         
  1055. X    }
  1056. X
  1057. X  if (inserts)
  1058. X    {
  1059. X      fprintf (outfile, "a");
  1060. X
  1061. X      /* Take last-line-number from file 0 and # lines from file 1.  */
  1062. X      translate_range (&files[1], f1, l1, &tf1, &tl1);
  1063. X      fprintf (outfile, "%d %d\n",
  1064. X           tl0,
  1065. X           (tl1 >= tf1 ? tl1 - tf1 + 1 : 1));         
  1066. X
  1067. X      /* Print the inserted lines.  */
  1068. X      for (i = f1; i <= l1; i++)
  1069. X    print_1_line ("", &files[1].linbuf[i]);
  1070. X    }
  1071. X}
  1072. END_OF_FILE
  1073. if test 5254 -ne `wc -c <'ed.c'`; then
  1074.     echo shar: \"'ed.c'\" unpacked with wrong size!
  1075. fi
  1076. # end of 'ed.c'
  1077. fi
  1078. if test -f 'getopt.h' -a "${1}" != "-c" ; then 
  1079.   echo shar: Will not clobber existing file \"'getopt.h'\"
  1080. else
  1081. echo shar: Extracting \"'getopt.h'\" \(3554 characters\)
  1082. sed "s/^X//" >'getopt.h' <<'END_OF_FILE'
  1083. X/* declarations for getopt
  1084. X   Copyright (C) 1989, 1990 Free Software Foundation, Inc.
  1085. X
  1086. X   This program is free software; you can redistribute it and/or modify
  1087. X   it under the terms of the GNU General Public License as published by
  1088. X   the Free Software Foundation; either version 1, or (at your option)
  1089. X   any later version.
  1090. X
  1091. X   This program is distributed in the hope that it will be useful,
  1092. X   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1093. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1094. X   GNU General Public License for more details.
  1095. X
  1096. X   You should have received a copy of the GNU General Public License
  1097. X   along with this program; if not, write to the Free Software
  1098. X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1099. X
  1100. X/* For communication from `getopt' to the caller.
  1101. X   When `getopt' finds an option that takes an argument,
  1102. X   the argument value is returned here.
  1103. X   Also, when `ordering' is RETURN_IN_ORDER,
  1104. X   each non-option ARGV-element is returned here.  */
  1105. X
  1106. Xextern char *optarg;
  1107. X
  1108. X/* Index in ARGV of the next element to be scanned.
  1109. X   This is used for communication to and from the caller
  1110. X   and for communication between successive calls to `getopt'.
  1111. X
  1112. X   On entry to `getopt', zero means this is the first call; initialize.
  1113. X
  1114. X   When `getopt' returns EOF, this is the index of the first of the
  1115. X   non-option elements that the caller should itself scan.
  1116. X
  1117. X   Otherwise, `optind' communicates from one call to the next
  1118. X   how much of ARGV has been scanned so far.  */
  1119. X
  1120. Xextern int optind;
  1121. X
  1122. X/* Callers store zero here to inhibit the error message `getopt' prints
  1123. X   for unrecognized options.  */
  1124. X
  1125. Xextern int opterr;
  1126. X
  1127. X/* Describe the long-named options requested by the application.
  1128. X   _GETOPT_LONG_OPTIONS is a vector of `struct option' terminated by an
  1129. X   element containing a name which is zero.
  1130. X
  1131. X   The field `has_arg' is:
  1132. X   0 if the option does not take an argument,
  1133. X   1 if the option requires an argument,
  1134. X   2 if the option takes an optional argument.
  1135. X
  1136. X   If the field `flag' is nonzero, it points to a variable that is set
  1137. X   to the value given in the field `val' when the option is found, but
  1138. X   left unchanged if the option is not found.
  1139. X
  1140. X   To have a long-named option do something other than set an `int' to
  1141. X   a compiled-in constant, such as set a value from `optarg', set the
  1142. X   option's `flag' field to zero and its `val' field to a nonzero
  1143. X   value (the equivalent single-letter option character, if there is
  1144. X   one).  For long options that have a zero `flag' field, `getopt'
  1145. X   returns the contents of the `val' field.  */
  1146. X
  1147. Xstruct option
  1148. X{
  1149. X  char *name;
  1150. X  int has_arg;
  1151. X  int *flag;
  1152. X  int val;
  1153. X};
  1154. X
  1155. X#ifdef __STDC__
  1156. Xextern const struct option *_getopt_long_options;
  1157. X#else
  1158. Xextern struct option *_getopt_long_options;
  1159. X#endif
  1160. X
  1161. X/* If nonzero, '-' can introduce long-named options.
  1162. X   Set by getopt_long_only.  */
  1163. X
  1164. Xextern int _getopt_long_only;
  1165. X
  1166. X/* The index in GETOPT_LONG_OPTIONS of the long-named option found.
  1167. X   Only valid when a long-named option has been found by the most
  1168. X   recent call to `getopt'.  */
  1169. X
  1170. Xextern int option_index;
  1171. X
  1172. X#ifdef __STDC__
  1173. Xint getopt (int argc, char **argv, const char *shortopts);
  1174. Xint getopt_long (int argc, char **argv, const char *shortopts,
  1175. X         const struct option *longopts, int *longind);
  1176. Xint getopt_long_only (int argc, char **argv, const char *shortopts,
  1177. X              const struct option *longopts, int *longind);
  1178. Xvoid envopt(int *pargc, char ***pargv, char *optstr);
  1179. X#else
  1180. Xint getopt ();
  1181. Xint getopt_long ();
  1182. Xint getopt_long_only ();
  1183. Xvoid envopt();
  1184. X#endif
  1185. END_OF_FILE
  1186. if test 3554 -ne `wc -c <'getopt.h'`; then
  1187.     echo shar: \"'getopt.h'\" unpacked with wrong size!
  1188. fi
  1189. # end of 'getopt.h'
  1190. fi
  1191. if test -f 'getopt1.c' -a "${1}" != "-c" ; then 
  1192.   echo shar: Will not clobber existing file \"'getopt1.c'\"
  1193. else
  1194. echo shar: Extracting \"'getopt1.c'\" \(3388 characters\)
  1195. sed "s/^X//" >'getopt1.c' <<'END_OF_FILE'
  1196. X/* Getopt for GNU.
  1197. X   Copyright (C) 1987, 1989 Free Software Foundation, Inc.
  1198. X
  1199. X   This program is free software; you can redistribute it and/or modify
  1200. X   it under the terms of the GNU General Public License as published by
  1201. X   the Free Software Foundation; either version 1, or (at your option)
  1202. X   any later version.
  1203. X
  1204. X   This program is distributed in the hope that it will be useful,
  1205. X   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1206. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1207. X   GNU General Public License for more details.
  1208. X
  1209. X   You should have received a copy of the GNU General Public License
  1210. X   along with this program; if not, write to the Free Software
  1211. X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1212. X
  1213. X#include "getopt.h"
  1214. X
  1215. X#ifdef __STDC__
  1216. X#define CONST const
  1217. X#else
  1218. X#define CONST
  1219. X#endif
  1220. X
  1221. X#if !defined (NULL)
  1222. X#define NULL 0
  1223. X#endif
  1224. X
  1225. Xint
  1226. Xgetopt_long (argc, argv, options, long_options, opt_index)
  1227. X     int argc;
  1228. X     char **argv;
  1229. X     CONST char *options;
  1230. X     CONST struct option *long_options;
  1231. X     int *opt_index;
  1232. X{
  1233. X  int val;
  1234. X
  1235. X  _getopt_long_options = long_options;
  1236. X  val = getopt (argc, argv, options);
  1237. X  if (val == 0 && opt_index != NULL)
  1238. X    *opt_index = option_index;
  1239. X  return val;
  1240. X}
  1241. X
  1242. X/* Like getopt_long, but '-' as well as '+' can indicate a long option.
  1243. X   If an option that starts with '-' doesn't match a long option,
  1244. X   but does match a short option, it is parsed as a short option
  1245. X   instead. */
  1246. X
  1247. Xint 
  1248. Xgetopt_long_only (argc, argv, options, long_options, opt_index)
  1249. X     int argc;
  1250. X     char **argv;
  1251. X     CONST char *options;
  1252. X     CONST struct option *long_options;
  1253. X     int *opt_index;
  1254. X{
  1255. X  int val;
  1256. X
  1257. X  _getopt_long_options = long_options;
  1258. X  _getopt_long_only = 1;
  1259. X  val = getopt (argc, argv, options);
  1260. X  if (val == 0 && opt_index != NULL)
  1261. X    *opt_index = option_index;
  1262. X  return val;
  1263. X}
  1264. X
  1265. X
  1266. X#ifdef TEST
  1267. X
  1268. X#include <stdio.h>
  1269. X
  1270. Xint
  1271. Xmain (argc, argv)
  1272. X     int argc;
  1273. X     char **argv;
  1274. X{
  1275. X  int c;
  1276. X  int digit_optind = 0;
  1277. X
  1278. X  while (1)
  1279. X    {
  1280. X      int this_option_optind = optind ? optind : 1;
  1281. X      char *name = '\0';
  1282. X      int option_index = 0;
  1283. X      static struct option long_options[] =
  1284. X      {
  1285. X    {"add", 1, 0, 0},
  1286. X    {"append", 0, 0, 0},
  1287. X    {"delete", 1, 0, 0},
  1288. X    {"verbose", 0, 0, 0},
  1289. X    {"create", 0, 0, 0},
  1290. X    {"file", 1, 0, 0},
  1291. X    {0, 0, 0, 0}
  1292. X      };
  1293. X
  1294. X      c = getopt_long (argc, argv, "abc:d:0123456789",
  1295. X               long_options, &option_index);
  1296. X      if (c == EOF)
  1297. X    break;
  1298. X
  1299. X      switch (c)
  1300. X    {
  1301. X    case 0:
  1302. X      printf ("option %s", (long_options[option_index]).name);
  1303. X      if (optarg)
  1304. X        printf (" with arg %s", optarg);
  1305. X      printf ("\n");
  1306. X      break;
  1307. X
  1308. X    case '0':
  1309. X    case '1':
  1310. X    case '2':
  1311. X    case '3':
  1312. X    case '4':
  1313. X    case '5':
  1314. X    case '6':
  1315. X    case '7':
  1316. X    case '8':
  1317. X    case '9':
  1318. X      if (digit_optind != 0 && digit_optind != this_option_optind)
  1319. X        printf ("digits occur in two different argv-elements.\n");
  1320. X      digit_optind = this_option_optind;
  1321. X      printf ("option %c\n", c);
  1322. X      break;
  1323. X
  1324. X    case 'a':
  1325. X      printf ("option a\n");
  1326. X      break;
  1327. X
  1328. X    case 'b':
  1329. X      printf ("option b\n");
  1330. X      break;
  1331. X
  1332. X    case 'c':
  1333. X      printf ("option c with value `%s'\n", optarg);
  1334. X      break;
  1335. X
  1336. X    case '?':
  1337. X      break;
  1338. X
  1339. X    default:
  1340. X      printf ("?? getopt returned character code 0%o ??\n", c);
  1341. X    }
  1342. X    }
  1343. X
  1344. X  if (optind < argc)
  1345. X    {
  1346. X      printf ("non-option ARGV-elements: ");
  1347. X      while (optind < argc)
  1348. X    printf ("%s ", argv[optind++]);
  1349. X      printf ("\n");
  1350. X    }
  1351. X
  1352. X  exit (0);
  1353. X}
  1354. X
  1355. X#endif /* TEST */
  1356. END_OF_FILE
  1357. if test 3388 -ne `wc -c <'getopt1.c'`; then
  1358.     echo shar: \"'getopt1.c'\" unpacked with wrong size!
  1359. fi
  1360. # end of 'getopt1.c'
  1361. fi
  1362. if test -f 'ifdef.c' -a "${1}" != "-c" ; then 
  1363.   echo shar: Will not clobber existing file \"'ifdef.c'\"
  1364. else
  1365. echo shar: Extracting \"'ifdef.c'\" \(2564 characters\)
  1366. sed "s/^X//" >'ifdef.c' <<'END_OF_FILE'
  1367. X/* #ifdef-format output routines for GNU DIFF.
  1368. X   Copyright (C) 1989 Free Software Foundation, Inc.
  1369. X
  1370. XThis file is part of GNU DIFF.
  1371. X
  1372. XGNU DIFF is distributed in the hope that it will be useful,
  1373. Xbut WITHOUT ANY WARRANTY.  No author or distributor
  1374. Xaccepts responsibility to anyone for the consequences of using it
  1375. Xor for whether it serves any particular purpose or works at all,
  1376. Xunless he says so in writing.  Refer to the GNU DIFF General Public
  1377. XLicense for full details.
  1378. X
  1379. XEveryone is granted permission to copy, modify and redistribute
  1380. XGNU DIFF, but only under the conditions described in the
  1381. XGNU DIFF General Public License.   A copy of this license is
  1382. Xsupposed to have been given to you along with GNU DIFF so you
  1383. Xcan know your rights and responsibilities.  It should be in a
  1384. Xfile named COPYING.  Among other things, the copyright notice
  1385. Xand this notice must be preserved on all copies.  */
  1386. X
  1387. X
  1388. X#include "diff.h"
  1389. X
  1390. Xstatic void print_ifdef_hunk ();
  1391. Xstruct change *find_change ();
  1392. X
  1393. Xstatic int next_line;
  1394. X
  1395. X/* Print the edit-script SCRIPT as a merged #ifdef file.  */
  1396. X
  1397. Xvoid
  1398. Xprint_ifdef_script (script)
  1399. X     struct change *script;
  1400. X{
  1401. X  next_line = 0;
  1402. X  print_script (script, find_change, print_ifdef_hunk);
  1403. X  while (next_line < files[0].buffered_lines)
  1404. X    print_1_line ("", &files[0].linbuf[next_line++]);
  1405. X}
  1406. X
  1407. X/* Print a hunk of an ifdef diff.
  1408. X   This is a contiguous portion of a complete edit script,
  1409. X   describing changes in consecutive lines.  */
  1410. X
  1411. Xstatic void
  1412. Xprint_ifdef_hunk (hunk)
  1413. X     struct change *hunk;
  1414. X{
  1415. X  int first0, last0, first1, last1, deletes, inserts;
  1416. X  register int i;
  1417. X
  1418. X  /* Determine range of line numbers involved in each file.  */
  1419. X  analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts);
  1420. X  if (!deletes && !inserts)
  1421. X    return;
  1422. X
  1423. X  /* Print out lines up to this change.  */
  1424. X  while (next_line < first0)
  1425. X    print_1_line ("", &files[0].linbuf[next_line++]);
  1426. X
  1427. X  /* Print out stuff deleted from first file.  */
  1428. X  if (deletes)
  1429. X    {
  1430. X      fprintf (outfile, "#ifndef %s\n", ifdef_string);
  1431. X      for (i = first0; i <= last0; i++)
  1432. X    print_1_line ("", &files[0].linbuf[i]);
  1433. X      next_line = i;
  1434. X    }
  1435. X
  1436. X  /* Print out stuff inserted from second file.  */
  1437. X  if (inserts)
  1438. X    {
  1439. X      if (deletes)
  1440. X    fprintf (outfile, "#else /* %s */\n", ifdef_string);
  1441. X      else
  1442. X    fprintf (outfile, "#ifdef %s\n", ifdef_string);
  1443. X      for (i = first1; i <= last1; i++)
  1444. X    print_1_line ("", &files[1].linbuf[i]);
  1445. X    }
  1446. X
  1447. X  if (inserts)
  1448. X    fprintf (outfile, "#endif /* %s */\n", ifdef_string);
  1449. X  else
  1450. X    fprintf (outfile, "#endif /* not %s */\n", ifdef_string);
  1451. X}
  1452. END_OF_FILE
  1453. if test 2564 -ne `wc -c <'ifdef.c'`; then
  1454.     echo shar: \"'ifdef.c'\" unpacked with wrong size!
  1455. fi
  1456. # end of 'ifdef.c'
  1457. fi
  1458. if test -f 'limits.h' -a "${1}" != "-c" ; then 
  1459.   echo shar: Will not clobber existing file \"'limits.h'\"
  1460. else
  1461. echo shar: Extracting \"'limits.h'\" \(1170 characters\)
  1462. sed "s/^X//" >'limits.h' <<'END_OF_FILE'
  1463. X/* Number of bits in a `char'.  */
  1464. X#define CHAR_BIT 8
  1465. X
  1466. X/* No multibyte characters supported yet.  */
  1467. X#define MB_LEN_MAX 1
  1468. X
  1469. X/* Minimum and maximum values a `signed char' can hold.  */
  1470. X#define SCHAR_MIN (-128)
  1471. X#define SCHAR_MAX 127
  1472. X
  1473. X/* Maximum value an `unsigned char' can hold.  (Minimum is 0).  */
  1474. X#define UCHAR_MAX 255U
  1475. X
  1476. X/* Minimum and maximum values a `char' can hold.  */
  1477. X#ifdef __CHAR_UNSIGNED__
  1478. X#define CHAR_MIN 0
  1479. X#define CHAR_MAX 255U
  1480. X#else
  1481. X#define CHAR_MIN (-128)
  1482. X#define CHAR_MAX 127
  1483. X#endif
  1484. X
  1485. X/* Minimum and maximum values a `signed short int' can hold.  */
  1486. X#define SHRT_MIN (-32768)
  1487. X#define SHRT_MAX 32767
  1488. X
  1489. X/* Maximum value an `unsigned short int' can hold.  (Minimum is 0).  */
  1490. X#define USHRT_MAX 65535U
  1491. X
  1492. X/* Minimum and maximum values a `signed int' can hold.  */
  1493. X#define INT_MIN (-INT_MAX-1)
  1494. X#define INT_MAX 2147483647
  1495. X
  1496. X/* Maximum value an `unsigned int' can hold.  (Minimum is 0).  */
  1497. X#define UINT_MAX 4294967295U
  1498. X
  1499. X/* Minimum and maximum values a `signed long int' can hold.
  1500. X   (Same as `int').  */
  1501. X#define LONG_MIN (-LONG_MAX-1)
  1502. X#define LONG_MAX 2147483647
  1503. X
  1504. X/* Maximum value an `unsigned long int' can hold.  (Minimum is 0).  */
  1505. X#define ULONG_MAX 4294967295U
  1506. END_OF_FILE
  1507. if test 1170 -ne `wc -c <'limits.h'`; then
  1508.     echo shar: \"'limits.h'\" unpacked with wrong size!
  1509. fi
  1510. # end of 'limits.h'
  1511. fi
  1512. if test -f 'normal.c' -a "${1}" != "-c" ; then 
  1513.   echo shar: Will not clobber existing file \"'normal.c'\"
  1514. else
  1515. echo shar: Extracting \"'normal.c'\" \(2210 characters\)
  1516. sed "s/^X//" >'normal.c' <<'END_OF_FILE'
  1517. X/* Normal-format output routines for GNU DIFF.
  1518. X   Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  1519. X
  1520. XThis file is part of GNU DIFF.
  1521. X
  1522. XGNU DIFF is free software; you can redistribute it and/or modify
  1523. Xit under the terms of the GNU General Public License as published by
  1524. Xthe Free Software Foundation; either version 1, or (at your option)
  1525. Xany later version.
  1526. X
  1527. XGNU DIFF is distributed in the hope that it will be useful,
  1528. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  1529. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1530. XGNU General Public License for more details.
  1531. X
  1532. XYou should have received a copy of the GNU General Public License
  1533. Xalong with GNU DIFF; see the file COPYING.  If not, write to
  1534. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1535. X
  1536. X
  1537. X#include "diff.h"
  1538. X
  1539. Xvoid print_normal_hunk ();
  1540. Xvoid print_number_range ();
  1541. Xstruct change *find_change ();
  1542. X
  1543. X/* Print the edit-script SCRIPT as a normal diff.
  1544. X   INF points to an array of descriptions of the two files.  */
  1545. X
  1546. Xvoid
  1547. Xprint_normal_script (script)
  1548. X     struct change *script;
  1549. X{
  1550. X  print_script (script, find_change, print_normal_hunk);
  1551. X}
  1552. X
  1553. X/* Print a hunk of a normal diff.
  1554. X   This is a contiguous portion of a complete edit script,
  1555. X   describing changes in consecutive lines.  */
  1556. X
  1557. Xvoid
  1558. Xprint_normal_hunk (hunk)
  1559. X     struct change *hunk;
  1560. X{
  1561. X  int first0, last0, first1, last1, deletes, inserts;
  1562. X  register int i;
  1563. X
  1564. X  /* Determine range of line numbers involved in each file.  */
  1565. X  analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts);
  1566. X  if (!deletes && !inserts)
  1567. X    return;
  1568. X
  1569. X  /* Print out the line number header for this hunk */
  1570. X  print_number_range (',', &files[0], first0, last0);
  1571. X  fprintf (outfile, "%c", change_letter (inserts, deletes));
  1572. X  print_number_range (',', &files[1], first1, last1);
  1573. X  fprintf (outfile, "\n");
  1574. X
  1575. X  /* Print the lines that the first file has.  */
  1576. X  if (deletes)
  1577. X    for (i = first0; i <= last0; i++)
  1578. X      print_1_line ("<", &files[0].linbuf[i]);
  1579. X
  1580. X  if (inserts && deletes)
  1581. X    fprintf (outfile, "---\n");
  1582. X
  1583. X  /* Print the lines that the second file has.  */
  1584. X  if (inserts)
  1585. X    for (i = first1; i <= last1; i++)
  1586. X      print_1_line (">", &files[1].linbuf[i]);
  1587. X}
  1588. END_OF_FILE
  1589. if test 2210 -ne `wc -c <'normal.c'`; then
  1590.     echo shar: \"'normal.c'\" unpacked with wrong size!
  1591. fi
  1592. # end of 'normal.c'
  1593. fi
  1594. if test -f 'version.c' -a "${1}" != "-c" ; then 
  1595.   echo shar: Will not clobber existing file \"'version.c'\"
  1596. else
  1597. echo shar: Extracting \"'version.c'\" \(67 characters\)
  1598. sed "s/^X//" >'version.c' <<'END_OF_FILE'
  1599. X/* Version number of GNU diff.  */
  1600. X
  1601. Xchar *version_string = "1.15";
  1602. END_OF_FILE
  1603. if test 67 -ne `wc -c <'version.c'`; then
  1604.     echo shar: \"'version.c'\" unpacked with wrong size!
  1605. fi
  1606. # end of 'version.c'
  1607. fi
  1608. echo shar: End of archive 1 \(of 8\).
  1609. cp /dev/null ark1isdone
  1610. MISSING=""
  1611. for I in 1 2 3 4 5 6 7 8 ; do
  1612.     if test ! -f ark${I}isdone ; then
  1613.     MISSING="${MISSING} ${I}"
  1614.     fi
  1615. done
  1616. if test "${MISSING}" = "" ; then
  1617.     echo You have unpacked all 8 archives.
  1618.     rm -f ark[1-9]isdone
  1619. else
  1620.     echo You still need to unpack the following archives:
  1621.     echo "        " ${MISSING}
  1622. fi
  1623. ##  End of shell archive.
  1624. exit 0
  1625.  
  1626. exit 0 # Just in case...
  1627.